package com.laikan.reader.bookfriend.net;

import com.google.gson.internal.$Gson$Types;
import com.laikan.library.httpvolley.helper.VolleyErrorHandler;
import com.laikan.library.httpvolley.response.HttpResponse;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * Created by lingyt on 2016/11/3.
 * 在RequestListener基础上 自定义CallBack
 */
public abstract class BaseCallback<T> {

    public Type mType;

    static Type getSuperclassTypeParameter(Class<?> subclass)
    {
        Type superclass = subclass.getGenericSuperclass();
        if (superclass instanceof Class)
        {
            throw new RuntimeException("Missing type parameter.");
        }
        ParameterizedType parameterized = (ParameterizedType) superclass;
        return $Gson$Types.canonicalize(parameterized.getActualTypeArguments()[0]);
    }


    public BaseCallback()
    {
        mType = getSuperclassTypeParameter(getClass());
    }

    public abstract void onPreExecute();

    public abstract void onSuccess(HttpResponse httpResponse, T t);

    public abstract void onError(VolleyErrorHandler errorHandler);

    public abstract void onFinish();



}
